<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
     
%>
<!DOCTYPE html>
<html>
    <head>
    	<base href="<%=basePath%>">
        <meta charset="utf-8">
        <title>添加账号信息</title>
        <link rel="shortcut icon" href="public/image/favicon.png">
        <link rel="stylesheet" type="text/css" href="public/style/cssreset-min.css">
        <link rel="stylesheet" type="text/css" href="public/style/common.css">
        <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	    <link rel="stylesheet" href="bootstrap-table/dist/bootstrap-table.css">
	    
	    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
	    <link rel="stylesheet" href="css/font.css">
	    
	    <link rel="stylesheet" href="./css/x-admin.css" media="all">
        <style type="text/css">
            .citys{
                margin-bottom: 10px;
            }
            .citys p{
                line-height: 28px;
            }
            .warning{
                color: #c00;
            }
            .main a{
                margin-right: 8px;
                color: #369;
            }
        </style>
        
        <script src="js/jquery-3.2.1.min.js"></script>
        <script src="js/common2.js"></script>
        <script type="text/javascript" src="public/script/jquery.min.js"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="js/jquery-bootstrap-pagination.js"></script>
	    <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
		<script src="js/qunit-1.11.0.js"></script>
		<script src="bootstrap-table/dist/bootstrap-table.min.js"></script>
		<script src="bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
		
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script src="./js/x-layui.js" charset="utf-8"></script>
        
    </head>
    <body>
        <div class="x-body">
        	<div class="form-horizontal" role="form">
        	
	        	  <div class="form-group">
				    <label for="firstname" class="col-sm-2 control-label">姓名:</label>
				    <div class="col-sm-3">
				      <input type="text" class="form-control" id="username" name="username"  placeholder="请输入姓名"/>
				    </div>
				  </div>
				  
				  <div class="form-group">
				    <label for="firstname" class="col-sm-2 control-label">账号:</label>
				    <div class="col-sm-3">
				      <input type="text" class="form-control" id="account" name="account"  placeholder="请输入账号"/>
				    </div>
				 </div>
				 
				 <div class="form-group">
				    <label for="firstname" class="col-sm-2 control-label">密码:</label>
				    <div class="col-sm-3">
				      <input type="text" class="form-control" id="password" name="password"  placeholder="请输入密码"/>
				    </div>
				 </div>
				  
				  <div class="form-group">
				    <label for="firstname" class="col-sm-2 control-label">授予角色:</label>
				    <div class="col-sm-3">
				      <select id="role" class="form-control">
	              	  </select>
				    </div>
				  </div>
				  
				  <div class="form-group">
				    <label for="firstname" class="col-sm-2 control-label">状态:</label>
				    <div class="col-sm-3">
				      <select id="status" class="form-control">
	             		<option value="1">启用</option>
             			<option value="2">禁用</option>
	              	  </select>
				    </div>
				  </div>
	        	
			  <div class="form-group" style="padding-left: 30%">
        		<button type="submit"   onclick="save()"  class="btn btn-info" >保存</button>
        		<button type="reset"    onclick="cancel()"  class="btn btn-info" >取消 </button>
     		  </div>
	      </div>
       </div>
       
       <script type="text/javascript">
       
	       layui.use(['form','layer','upload'], function(){
	           $ = layui.jquery;
	         var form = layui.form()
	         ,layer = layui.layer;
	         });
       
       		//保存校区
       		function save(){
    	    	
   		   	 var username =	$("#username").val();
   		   	 if(username == null || username == "") {
   		   		layer.msg('姓名不能为空!',{icon:2,time:2000});
				  return ;
   		   	 }
   		  	var account = $("#account").val();
			 if(account == null || account == "") {
				layer.msg('账号不能为空!',{icon:2,time:2000});
				  return ;
		   	 }
			 var password =	$("#password").val();
			 if(password == null||password=="") {
				layer.msg('密码不能为空!',{icon:2,time:2000});
				  return ;
		   	 }
		 	var role_id = $("#role").find("option:selected").val();
		 	if(role_id == null||role_id=="") {
				layer.msg('授予角色不能为空!',{icon:2,time:2000});
				  return ;
		   	 }
		 	var status = $("#status").find("option:selected").val();
		 	if(status == null||status=="") {
				layer.msg('状态不能为空!',{icon:2,time:2000});
				  return ;
		   	 }
   		 
   			 var  data = {"username":username,"account":account,"password":password,"role_id":role_id,"status":status}
   	         
   	         $.ajax({
   	             type: "post",
   	             url: "role/addSysUser",
   	             data: JSON.stringify(data),
   	             contentType:"application/json;charset=UTF-8", 
   	             dataType:"json",
   	             success: function(data){    
   	           	  if(data.code==200){
   	           	layer.alert("增加成功", {icon: 6},function () {
   	           		parent.location.reload();
	                    // 获得frame索引
	                    var index = parent.layer.getFrameIndex(window.name);
	                    //关闭当前frame
	                    parent.layer.close(index);
	                     parent.location.reload();
	                });    
	       		 }else{
		    	      var txt=data.msg;
		      	      layer.alert(txt); 
		      	 }
               }
   	         });  
   	         
   			}
   	   
       		//取消
	   	    function cancel(){
	   			// 获得frame索引
	        	 var index = parent.layer.getFrameIndex(window.name);
	           	//关闭当前frame
	           	parent.layer.close(index);
	   		}
       
	   	//角色列表
	   	   	$(function(){
	   	   		 $.ajax({
	   	               type: "get",
	   	               url: "role/roleList?type=1",
	   	               dataType:"json",
	   	               success: function(data){    
	   	             	  if(data.code==200){	           	              
	   	             		var htm='';
	   	             		    htm +='<option value="">请选择</option>';
	   	            		for (var i = 0; i < data.data.length; i++) {
	   	   	   				var bean = data.data;
	   	   	   				htm +='<option value="'+bean[i].G_ID+'" code="'+bean[i].G_ROLE_NAME+'">'+bean[i].G_ROLE_NAME+'</option>';
	   	     				}
	   	            		$("#role").html(htm);
	   	          	 	  }
	   	        	      
	   	               }
	   	           });  
	   	   	});
       
       </script>
    </body>
</html>
